<template>
	<view class="newstorageDetails">
		<Login></Login>
		<view class="searchpage" style="padding: 66rpx 38rpx 0 40rpx; box-sizing: border-box">
			<div style="display: flex; justify-content: space-between;">
				<div class="searchpage-top" style="font-size: 30rpx; font-weight: 600;">
					<input type="text" value="" placeholder="新的收纳箱" v-model="boxData.boxName" />
				</div>
				<div class="searchpage-top">
					<input type="text" value="" placeholder="大型" v-model="boxData.boxIntroduce" />
				</div>
				<div style="display: flex;">
					<view class="">
						<text class="text2">编辑使用者</text>
					</view>
				</div>
			</div>

			<view class="" style="width: 600rpx;display: flex;justify-content: space-between;box-sizing: border-box; padding-top: 42rpx; ">
				<swiper class="swiper" navigation :indicator-dots="true" :autoplay="true" :interval="2500" :duration="1000">
					<swiper-item v-for="(item,index) in bannerList" :key="index">
						<view class="swiper-item">
							<image :src=item mode=""></image>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<view class="" style="margin-top: 60rpx; height: 70rpx; display: flex;justify-content: center;">
				<view class="look" style="" @click="getNewBox">
					<text>放置箱子</text>
				</view>
			</view>
			<view class="" style="margin-top: 40rpx;display: flex;" @click="getaddress">
				<text class="icon iconfont icon-ditu-dibiao "></text>
				<input class="addressInput" style="" v-model="address" type="text" placeholder="请输入放置地点……" />
			</view>
			<view class="addfooter" @click="toNewLy">
				<text>添加物品</text>
				<text class="icon1 iconfont icon-tianjia "></text>
			</view>
		</view>
	</view>
</template>

<script>
	import Login from "../../common/login/login.vue"
	import BaseUrl from "../../utlis/api.js"
	export default {
		components: {
			Login
		},
		data() {
			return {
				list: [],
				bannerList: ["../../static/image/background.png"],
				boxData: {
					boxName: null,
					boxIntroduce: null,
					createTime: null,
					userId: null,
					boxState: null
				},
				address: ""
			}
		},
		onLoad(option) {},
		methods: {
			getNewBox() {
				if (this.boxData.boxName || this.boxData.boxIntroduce) {
					const token = wx.getStorageSync('token') || [];
					const userId = wx.getStorageSync('userId')
					const createTime = new Date().format("yyyy-MM-dd hh:mm:ss"); //创建时间
					this.boxData.userId = userId
					this.boxData.createTime = createTime
					this.boxData.boxQrCode = this.address
					console.log(this.boxData)
					uni.request({
						url: BaseUrl + "/wx/sbox/box",
						method: 'POST',
						data: this.boxData,
						header: {
							"Authorization": "Bearer " + token,
						},
						success: (res) => {
							console.log(res)
							if (res.data.code == 200) {
								uni.showToast({
									title: res.data.msg
								});
								let pages = getCurrentPages(); // 当前页面
								let beforePage = pages[pages.length - 2]; // 上一页
								uni.navigateBack({
									success: function() {
										beforePage.onLoad(); // 执行上一页的onLoad方法
									}
								});
							}
						}
					})
				} else {
					uni.showToast({
						title: "请输入名称和类型"
					});
				}

			},
			toNewLy() {
				uni.navigateTo({
					url: '/pages/newly/newly',
				})
			},
			getaddress() {
				this.address = wx.getStorageSync('address');

			}

		}
	}
</script>

<style>
	.newstorageDetails {
		width: 100%;
		height: 100%;
		background-color: #c3b18b;
	}

	.searchpage {
		width: 100%;
		height: 100%;
		background-color: #f9f7f2;
		border-radius: 20rpx;
	}

	.searchpage-top {
		width: 33%;
		height: 25px;
		font-size: 26rpx;
		font-family: PingFang SC;
		line-height: 26px;
		color: #000000;
		opacity: 0.7;
	}

	.text1 {
		width: 24px;
		height: 17px;
		font-size: 12px;
		font-family: PingFang SC;
		font-weight: bold;
		line-height: 26px;
		color: #000000;
		opacity: 0.6;
		margin-right: 20rpx;
	}

	.text2 {
		width: 48px;
		height: 17px;
		font-size: 12px;
		font-family: PingFang SC;
		font-weight: bold;
		line-height: 26px;
		color: #000000;
		opacity: 0.6;
	}

	.weui-cells {
		display: inline-block;
		width: 254px;
		height: 32px;
		border: 1px solid #000;
		opacity: 0.3;
		border-radius: 10px;
	}

	.mini-btn {
		width: 61px;
		height: 32px;
		margin-top: 70rpx;
		background: #ffcf00;
		opacity: 1;
		border-radius: 10px;
	}

	.whitebg {
		whitebgwidth: 120px;
		height: 40px;
		background: #fff;
		opacity: 0.9;
		border-radius: 10px;
		font-weight: 800;
		line-height: 52rpx;
		color: #000000;
		font-size: 24rpx;
		box-sizing: border-box;
		padding: 15rpx;
	}

	.swiper {
		width: 100%;
		height: 300rpx;
	}

	.look {
		width: 270rpx;
		height: 100%;
		background: #FFCF00;
		opacity: 1;
		border-radius: 36rpx;
		text-align: center;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 800;
		line-height: 70rpx;
		color: #FFFFFF;
		opacity: 1;
	}

	.icon {
		color: #FFCF00;
	}

	.icon1 {
		color: #707070;
		font-size: 60rpx;
	}

	.testt {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 26px;
		color: #000000;
		opacity: 1;
	}

	.addfooter {
		width: 100%;
		height: 83rpx;
		border-top: 1px solid #DEDDD9;
		border-bottom: 1px solid #DEDDD9;
		margin-top: 24rpx;
		line-height: 83rpx;
		display: flex;
		justify-content: space-between;
		box-sizing: border-box;
		padding-left: 20rpx;
		font-size: 32rpx;
	}

	.addressInput {
		width: 80%;
		margin-left: 20rpx;
		font-size: 28rpx;
		padding-top: 10rpx;
		color: #333;
	}
</style>
